package com.yaoxuguang.concurrence.mic;

import java.util.concurrent.TimeUnit;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence
 * @Description: 线程状态
 * @date 2018年12月14日15:37
 */
public class ThreadStatus {
    public static void main(String[] args) {
        //TIME_WAITING 超时等待
        new Thread(()->{
            while (true){
                try {
                    TimeUnit.SECONDS.sleep(100);
                    System.out.println(Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"TIME_WAITING").start();

        new Thread(()->{
            while (true){
                synchronized (ThreadStatus.class){
                    try {
                        ThreadStatus.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        },"waiting").start();

        new Thread(new BlockedDemo(),"blockedDemo-01").start();
        new Thread(new BlockedDemo(),"blockedDemo-02").start();

    }

    static class BlockedDemo extends Thread{
        @Override
        public void run(){
            synchronized (BlockedDemo.class){
                while (true){
                    try {
                        TimeUnit.SECONDS.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
